//
//  WBRefreshView.m
//  weibo110
//
//  Created by 臧松 on 16/1/12.
//  Copyright © 2016年 臧松. All rights reserved.
//

#import "WBRefreshView.h"

@implementation WBRefreshView
-(void)setRotateFlag:(BOOL)rotateFlag{
    _rotateFlag = rotateFlag;
    [self rotateTipIcon];
}
+(instancetype)refreshView{
    
    UINib *nib = [UINib nibWithNibName:@"WBRefreshView" bundle:nil];
    return [nib instantiateWithOwner:nil options:nil].firstObject;
}
-(void)rotateTipIcon{
    float angle = M_PI;
    angle += self.rotateFlag? -0.000001:0.000001;
    
    [UIView animateWithDuration:0.5 animations:^{
        self.tipIconView.transform = CGAffineTransformRotate(self.tipIconView.transform, angle);
    }];
}
-(void)startAnimation{
    self.tipView.hidden = YES;
    NSString  * key = @"transform.rotation";
    if ([self.loadingIconView.layer animationForKey:key]) {
        return;
    }
    CABasicAnimation  * anim = [CABasicAnimation animationWithKeyPath:key];
    anim.toValue = [NSNumber numberWithFloat: 2* M_PI];
    anim.repeatCount = MAXFLOAT;
    anim.duration = 0.5;
    anim.removedOnCompletion = NO;
    
    [self.loadingIconView.layer addAnimation:anim forKey:key];
}
- (void)stopAnimation{
    self.tipView.hidden = NO;
    [self.loadingIconView.layer removeAllAnimations];
}
@end
